package com.example.hssmgs.Student;

import com.example.hssmgs.R;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.StackView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class show_info extends AppCompatActivity {

    SQLiteDatabase db;
    String student_account;
    String string_id;
    Button go_back;

    @SuppressLint("Range")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.show_info);

        // 获取用户信息
        final Intent about_me_intent = getIntent();
        student_account = about_me_intent.getStringExtra("student_id");
        string_id = "";
        //获取数据库对象
        db = new CommonDatabase().getSqliteObject(show_info.this, "test_db");

        TextView s_about_account = findViewById(R.id.show_account);
        TextView s_about_id = findViewById(R.id.show_id);
//        s_about_account.setText(student_account);

        @SuppressLint("Recycle") Cursor cursor_about = db.query("student_db",null,"account = ?",new String[]{about_me_intent.getStringExtra("student_id")},null,null,null);
        while(cursor_about.moveToNext())
        {
            //将通过id查询到的学生信息显示到界面中
            s_about_account.setText(cursor_about.getString(cursor_about.getColumnIndex("account")));
            s_about_id.setText(cursor_about.getString(cursor_about.getColumnIndex("id")));
        }


        go_back=findViewById(R.id.go_back);
        go_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });


//        mydata=getData();
//        recyclerView=findViewById(R.id.recyclerview);
//        recyclerView.setLayoutManager(new LinearLayoutManager(this));
//        recyclerView.setAdapter(new MyAdapter());

    }
//
//    //提供数据的函数
//    @SuppressLint("Range")
//    private List<Map<String, Object>> getData() {
//
//
//
//        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
//        Map<String, Object> map = new HashMap<String, Object>();
//        map.put("title", "学号");
//        map.put("info", student_account);
//        map.put("img", R.drawable.i1);
//        list.add(map);
//
////        map = new HashMap<String, Object>();
////        map.put("title", "id号");
////        map.put("info", string_id);
////        map.put("img", R.drawable.i2);
////        list.add(map);
//
////        map = new HashMap<String, Object>();
////        map.put("title", "英语");
////        map.put("info", "2022-09-14");
////        map.put("img", R.drawable.i3);
////        list.add(map);
//
//        return list;
//    }
//
//    class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder>{
//
//        @NonNull
//        @Override
//        public MyAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
//            View view= LayoutInflater.from(getApplicationContext()).inflate(R.layout.item,parent,false);
//            ViewHolder viewHolder=new ViewHolder(view);
//            return viewHolder;
//        }
//
//        @Override
//        public void onBindViewHolder(@NonNull MyAdapter.ViewHolder holder, int position) {
//            holder.title.setText((CharSequence)mydata.get(position).get("title"));
//            holder.info.setText((CharSequence)mydata.get(position).get("info"));
//            holder.img.setBackgroundResource((Integer)mydata.get(position).get("img"));
//        }
//
//        @Override
//        public int getItemCount() {
//            return mydata.size();
//        }
//
//        class ViewHolder extends RecyclerView.ViewHolder{
//            TextView title,info;
//            ImageView img;
//            public ViewHolder(@NonNull View itemView) {
//                super(itemView);
//                title=itemView.findViewById(R.id.title);
//                info=itemView.findViewById(R.id.info);
//                img=itemView.findViewById(R.id.img);
//            }
//        }
//
//    }

}

